

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/my-hexo-fluid/img/fluid.png">
  <link rel="icon" href="https://picgo-wskh.oss-cn-guangzhou.aliyuncs.com/avatar.jpg">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="WSKH0929">
  <meta name="keywords" content="">
  
    <meta name="description" content="1 Zookepper入门1.1 概述Zookeeper是一个开源的分布式的，为分布式应用提供协调服务的Apache项目。Zookeeper工作机制如下：  1.2 特点 1.3 数据结构 1.4 应用场景提供的服务包括：统一命名服务、统一配置管理、统一集群管理、服务器节点动态上下线、软负载均衡 等。 1.4.1 统一命名服务 1.4.2 统一配置服务 1.4.3 统一集群管理 1.4.4 服务器">
<meta property="og:type" content="article">
<meta property="og:title" content="Zookepper学习笔记">
<meta property="og:url" content="https://wskh0929.gitee.io/2023/01/01/Zookepper%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/index.html">
<meta property="og:site_name" content="WSKH0929 的博客">
<meta property="og:description" content="1 Zookepper入门1.1 概述Zookeeper是一个开源的分布式的，为分布式应用提供协调服务的Apache项目。Zookeeper工作机制如下：  1.2 特点 1.3 数据结构 1.4 应用场景提供的服务包括：统一命名服务、统一配置管理、统一集群管理、服务器节点动态上下线、软负载均衡 等。 1.4.1 统一命名服务 1.4.2 统一配置服务 1.4.3 统一集群管理 1.4.4 服务器">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/2021060318543665.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70">
<meta property="article:published_time" content="2023-01-01T13:02:54.000Z">
<meta property="article:modified_time" content="2022-12-31T08:00:31.890Z">
<meta property="article:author" content="WSKH0929">
<meta property="article:tag" content="Java">
<meta property="article:tag" content="Zookepper">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/2021060318543665.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>Zookepper学习笔记 - WSKH0929 的博客</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/my-hexo-fluid/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/my-hexo-fluid/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/my-hexo-fluid/css/highlight-dark.css" />
  



  
<link rel="stylesheet" href="//at.alicdn.com/t/c/font_3846514_kabxni94auf.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/bynotes/texiao/source/css/shubiao.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/bynotes/texiao/source/css/gundongtiao.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"wskh0929.gitee.io","root":"/my-hexo-fluid/","version":"1.9.4","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/my-hexo-fluid/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/my-hexo-fluid/js/utils.js" ></script>
  <script  src="/my-hexo-fluid/js/color-schema.js" ></script>
  

  

  

  

  

  

  

  



  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/my-hexo-fluid/">
      <strong>WSKH0929 的博客</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-hexo-fluid/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-hexo-fluid/archives">
                <i class="iconfont icon-books"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-hexo-fluid/categories">
                <i class="iconfont icon-th-large"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-hexo-fluid/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-hexo-fluid/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-hexo-fluid/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" target="_self" href="javascript:;" role="button"
                 data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="iconfont icon-book"></i>
                <span>文档</span>
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                
                  
                  
                  
                  <a class="dropdown-item" target="_blank" rel="noopener" href="https://hexo.fluid-dev.com/">
                    
                    <span>主题博客</span>
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_51545953/article/details/128499341?spm=1001.2014.3001.5501">
                    
                    <span>配置指南</span>
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" target="_blank" rel="noopener" href="https://hexo.fluid-dev.com/docs/icon/">
                    
                    <span>图标用法</span>
                  </a>
                
              </div>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/my-hexo-fluid/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Zookepper学习笔记"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        WSKH0929
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-01-01 21:02" pubdate>
           2023 年 01 月 01 日 , 晚上 09:02 , 星期日
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          <!-- compatible with older versions-->
          7.8k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          <!-- compatible with older versions-->
          66 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Zookepper学习笔记</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="1-Zookepper入门"><a href="#1-Zookepper入门" class="headerlink" title="1 Zookepper入门"></a>1 Zookepper入门</h1><h2 id="1-1-概述"><a href="#1-1-概述" class="headerlink" title="1.1 概述"></a>1.1 概述</h2><p>Zookeeper是一个开源的分布式的，为分布式应用提供协调服务的Apache项目。Zookeeper工作机制如下：</p>
<p><img src="https://img-blog.csdnimg.cn/20210602195317133.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<h2 id="1-2-特点"><a href="#1-2-特点" class="headerlink" title="1.2 特点"></a>1.2 特点</h2><p><img src="https://img-blog.csdnimg.cn/20210602195428937.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<h2 id="1-3-数据结构"><a href="#1-3-数据结构" class="headerlink" title="1.3 数据结构"></a>1.3 数据结构</h2><p><img src="https://img-blog.csdnimg.cn/20210602195524505.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<h2 id="1-4-应用场景"><a href="#1-4-应用场景" class="headerlink" title="1.4 应用场景"></a>1.4 应用场景</h2><p>提供的服务包括：<strong>统一命名服务、统一配置管理、统一集群管理、服务器节点动态上下线、软负载均衡</strong> 等。</p>
<h3 id="1-4-1-统一命名服务"><a href="#1-4-1-统一命名服务" class="headerlink" title="1.4.1 统一命名服务"></a>1.4.1 <strong>统一命名服务</strong></h3><p><img src="https://img-blog.csdnimg.cn/20210602195605452.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<h3 id="1-4-2-统一配置服务"><a href="#1-4-2-统一配置服务" class="headerlink" title="1.4.2 统一配置服务"></a>1.4.2 <strong>统一配置服务</strong></h3><p><img src="https://img-blog.csdnimg.cn/20210602195710142.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<h3 id="1-4-3-统一集群管理"><a href="#1-4-3-统一集群管理" class="headerlink" title="1.4.3 统一集群管理"></a>1.4.3 <strong>统一集群管理</strong></h3><p><img src="https://img-blog.csdnimg.cn/20210602195845543.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<h3 id="1-4-4-服务器节点动态上下线"><a href="#1-4-4-服务器节点动态上下线" class="headerlink" title="1.4.4 服务器节点动态上下线"></a>1.4.4 <strong>服务器节点动态上下线</strong></h3><p><img src="https://img-blog.csdnimg.cn/20210602195901738.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<h3 id="1-4-5-软负载均衡"><a href="#1-4-5-软负载均衡" class="headerlink" title="1.4.5 软负载均衡"></a>1.4.5 <strong>软负载均衡</strong></h3><p><img src="https://img-blog.csdnimg.cn/20210602195948828.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<h2 id="1-5-Zookepper安装"><a href="#1-5-Zookepper安装" class="headerlink" title="1.5 Zookepper安装"></a>1.5 Zookepper安装</h2><h3 id="1-5-1-下载地址"><a href="#1-5-1-下载地址" class="headerlink" title="1.5.1 下载地址"></a>1.5.1 下载地址</h3><p><a target="_blank" rel="noopener" href="https://zookeeper.apache.org/">https://zookeeper.apache.org/</a></p>
<h3 id="1-5-2-本地模式安装部署"><a href="#1-5-2-本地模式安装部署" class="headerlink" title="1.5.2 本地模式安装部署"></a>1.5.2 本地模式安装部署</h3><h4 id="①-安装前准备"><a href="#①-安装前准备" class="headerlink" title="① 安装前准备"></a>① 安装前准备</h4><p>▲ <strong>安装Jdk</strong></p>
<p><img src="https://img-blog.csdnimg.cn/20210602200251505.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<p>▲ <strong>拷贝Zookeeper安装包到Linux系统下</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">解压：tar -zxvf 压缩包名 目录   (解压到指定目录,不加目录默认当前目录)<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/2021060221155812.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<h4 id="②-配置修改"><a href="#②-配置修改" class="headerlink" title="② 配置修改"></a>② 配置修改</h4><p>▲ <strong>将/opt/zookeeper-3.4.10/conf这个路径下的zoo_sample.cfg修改为zoo.cfg；</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">mv</span> zoo_sample.cfg zoo.cfg<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/20210602211656576.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<p>▲ <strong>打开zoo.cfg文件，修改dataDir路径：</strong></p>
<p>需要手动创建 dataDir路径</p>
<p><img src="https://img-blog.csdnimg.cn/20210602211800176.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<p><img src="https://img-blog.csdnimg.cn/20210602211929541.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<h4 id="③-操作Zookeeper"><a href="#③-操作Zookeeper" class="headerlink" title="③ 操作Zookeeper"></a>③ 操作Zookeeper</h4><p><img src="https://img-blog.csdnimg.cn/20210602212100738.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload></p>
<p>▲ <strong>启动Zookeeper</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">bin/zkServer.sh start<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/20210602212302723.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p>▲ <strong>查看进程是否启动</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">jps<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/2021060221235272.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p>▲ <strong>查看状态：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">bin/zkServer.sh status<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/2021060221250221.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p>▲ <strong>启动客户端：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">bin/zkCli.sh<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/20210602212632321.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p><img src="https://img-blog.csdnimg.cn/20210602212803900.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p>▲ <strong>退出客户端：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">quit<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/20210602212825264.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p>▲ <strong>停止Zookeeper</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">bin/zkServer.sh stop<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/20210602212916594.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="1-5-3-配置参数解读"><a href="#1-5-3-配置参数解读" class="headerlink" title="1.5.3 配置参数解读"></a>1.5.3 配置参数解读</h3><p><img src="https://img-blog.csdnimg.cn/20210602213411293.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h1 id="2-Zookeeper-内部原理"><a href="#2-Zookeeper-内部原理" class="headerlink" title="2 Zookeeper 内部原理"></a>2 Zookeeper 内部原理</h1><h2 id="2-1-选举机制-★"><a href="#2-1-选举机制-★" class="headerlink" title="2.1 选举机制 (★)"></a>2.1 选举机制 (★)</h2><p><img src="https://img-blog.csdnimg.cn/2021060318465153.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p><img src="https://img-blog.csdnimg.cn/20210603184711431.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p><img src="https://img-blog.csdnimg.cn/20210603184732944.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h2 id="2-2-节点类型"><a href="#2-2-节点类型" class="headerlink" title="2.2 节点类型"></a>2.2 节点类型</h2><p><img src="https://img-blog.csdnimg.cn/20210603184915902.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h2 id="2-3-Stat-结构体"><a href="#2-3-Stat-结构体" class="headerlink" title="2.3 Stat 结构体"></a>2.3 Stat 结构体</h2><p><img src="https://img-blog.csdnimg.cn/20210603184944481.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h2 id="2-4-监听器原理-★"><a href="#2-4-监听器原理-★" class="headerlink" title="2.4 监听器原理 (★)"></a>2.4 监听器原理 (★)</h2><p><img src="https://img-blog.csdnimg.cn/20210603185215613.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h2 id="2-5-写数据流程"><a href="#2-5-写数据流程" class="headerlink" title="2.5 写数据流程"></a>2.5 写数据流程</h2><p><img src="https://img-blog.csdnimg.cn/2021060318543665.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h1 id="3-Zookeeper-实战-★"><a href="#3-Zookeeper-实战-★" class="headerlink" title="3 Zookeeper 实战 (★)"></a>3 Zookeeper 实战 (★)</h1><h2 id="3-1-分布式安装部署"><a href="#3-1-分布式安装部署" class="headerlink" title="3.1 分布式安装部署"></a>3.1 分布式安装部署</h2><p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/yjmyzz/p/4587663.html">在一台机器上模拟3个 zk server的集群安装</a></p>
<p><strong>前提</strong>：解压后zookeeper后，新建三个zkData，然后在conf中将zoo_sample.cfg改名，复制三份zoo配置文件</p>
<p><img src="https://img-blog.csdnimg.cn/20210603222709467.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p><img src="https://img-blog.csdnimg.cn/20210603222948308.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-1-1-配置服务器编号"><a href="#3-1-1-配置服务器编号" class="headerlink" title="3.1.1 配置服务器编号"></a>3.1.1 配置服务器编号</h3><p>在 zkData 文件夹下创建myid文件，内容分别为id值1，2，3</p>
<p><img src="https://img-blog.csdnimg.cn/20210603223057748.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°">\</p>
<h3 id="3-1-2-配置-zoo-cfg-文件"><a href="#3-1-2-配置-zoo-cfg-文件" class="headerlink" title="3.1.2 配置 zoo.cfg 文件"></a>3.1.2 配置 zoo.cfg 文件</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">server.1=192.168.44.129:2887:3887server.2=192.168.44.129:2888:3888server.3=192.168.44.129:2889:3889<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/20210603223257932.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p><img src="https://img-blog.csdnimg.cn/20210603223445283.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°">\</p>
<p><img src="https://img-blog.csdnimg.cn/20210603223411592.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p>配置参数解读：<code>server.A=B:C:D。</code></p>
<p><img src="https://img-blog.csdnimg.cn/20210602231323366.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-1-3-集群操作"><a href="#3-1-3-集群操作" class="headerlink" title="3.1.3 集群操作"></a>3.1.3 集群操作</h3><p>▲ <strong>分别启动Zookeeper</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 启动服务端bin/zkServer.sh start conf/zoo1.cfg# 启动对应服务端的客户端bin/zkCli.sh -server localhost:2182</span><br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/20210603223847181.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p>▲ <strong>查看状态</strong><br>( 根据之前的投票规则：正常情况下应该是 zookeeper-2 是 leader，1，3为follower ）</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">bin/zkServer.sh status conf/zoo1.cfg <br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/20210604113756188.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h2 id="3-2🔺-客户端命令行操作"><a href="#3-2🔺-客户端命令行操作" class="headerlink" title="3.2🔺 客户端命令行操作"></a>3.2🔺 客户端命令行操作</h2><p><img src="https://img-blog.csdnimg.cn/202106031306224.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-2-1-启动客户端"><a href="#3-2-1-启动客户端" class="headerlink" title="3.2.1 启动客户端"></a>3.2.1 启动客户端</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">bin/zkCli.shbin/zkCli.sh -server localhost:2182 <span class="hljs-comment">#指定某台server的客户端</span><br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/20210603130937697.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p><img src="https://img-blog.csdnimg.cn/20210604114113622.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-2-2-显示所有操作命令"><a href="#3-2-2-显示所有操作命令" class="headerlink" title="3.2.2 显示所有操作命令"></a>3.2.2 显示所有操作命令</h3><p><img src="https://img-blog.csdnimg.cn/20210603131401299.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-2-3-查看当前znode中所包含的内容"><a href="#3-2-3-查看当前znode中所包含的内容" class="headerlink" title="3.2.3 查看当前znode中所包含的内容"></a>3.2.3 查看当前znode中所包含的内容</h3><p><img src="https://img-blog.csdnimg.cn/20210603131617570.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-2-4-查看当前节点详细数据"><a href="#3-2-4-查看当前节点详细数据" class="headerlink" title="3.2.4 查看当前节点详细数据"></a>3.2.4 查看当前节点详细数据</h3><p><img src="https://img-blog.csdnimg.cn/20210603131634227.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-2-5-分别创建2个普通节点"><a href="#3-2-5-分别创建2个普通节点" class="headerlink" title="3.2.5 分别创建2个普通节点"></a>3.2.5 分别创建2个普通节点</h3><p><img src="https://img-blog.csdnimg.cn/20210603131847561.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-2-6-获得节点的值"><a href="#3-2-6-获得节点的值" class="headerlink" title="3.2.6 获得节点的值"></a>3.2.6 获得节点的值</h3><p><img src="https://img-blog.csdnimg.cn/20210603132056425.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p><img src="https://img-blog.csdnimg.cn/20210603132114350.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-2-7-创建短暂节点"><a href="#3-2-7-创建短暂节点" class="headerlink" title="3.2.7 创建短暂节点"></a>3.2.7 创建短暂节点</h3><p><img src="https://img-blog.csdnimg.cn/20210603132444373.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p><img src="https://img-blog.csdnimg.cn/20210603132554212.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-2-8-创建带序号的节点"><a href="#3-2-8-创建带序号的节点" class="headerlink" title="3.2.8 创建带序号的节点"></a>3.2.8 创建带序号的节点</h3><p><img src="https://img-blog.csdnimg.cn/20210603132949658.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-2-9-修改节点数据值"><a href="#3-2-9-修改节点数据值" class="headerlink" title="3.2.9 修改节点数据值"></a>3.2.9 修改节点数据值</h3><p><img src="https://img-blog.csdnimg.cn/20210603133231308.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°">\</p>
<h3 id="3-2-10-节点的值变化监听"><a href="#3-2-10-节点的值变化监听" class="headerlink" title="3.2.10 节点的值变化监听"></a>3.2.10 节点的值变化监听</h3><p><img src="https://img-blog.csdnimg.cn/20210603133420591.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-2-11-节点的子节点变化监听（路径变化）"><a href="#3-2-11-节点的子节点变化监听（路径变化）" class="headerlink" title="3.2.11 节点的子节点变化监听（路径变化）"></a>3.2.11 节点的子节点变化监听（路径变化）</h3><p><img src="https://img-blog.csdnimg.cn/20210603133819915.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-2-12-删除节点"><a href="#3-2-12-删除节点" class="headerlink" title="3.2.12 删除节点"></a>3.2.12 删除节点</h3><p><img src="https://img-blog.csdnimg.cn/20210603182446235.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-2-13-递归删除节点"><a href="#3-2-13-递归删除节点" class="headerlink" title="3.2.13 递归删除节点"></a>3.2.13 递归删除节点</h3><p><img src="https://img-blog.csdnimg.cn/20210603182604565.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°">\</p>
<h3 id="3-2-14-查看节点状态"><a href="#3-2-14-查看节点状态" class="headerlink" title="3.2.14 查看节点状态"></a>3.2.14 查看节点状态</h3><p><img src="https://img-blog.csdnimg.cn/20210603182647812.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h2 id="3-3-🔺-Zookepper-API-应用"><a href="#3-3-🔺-Zookepper-API-应用" class="headerlink" title="3.3 🔺 Zookepper  API 应用"></a>3.3 🔺 Zookepper  API 应用</h2><h3 id="3-3-1-创建一个-maven-工程"><a href="#3-3-1-创建一个-maven-工程" class="headerlink" title="3.3.1 创建一个 maven 工程"></a>3.3.1 创建一个 maven 工程</h3><p><img src="https://img-blog.csdnimg.cn/20210603191039756.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-3-2-添加-依赖"><a href="#3-3-2-添加-依赖" class="headerlink" title="3.3.2 添加 依赖"></a>3.3.2 添加 依赖</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span>	<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>		<span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>junit<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>		<span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>junit<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>		<span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>RELEASE<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>	<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>	<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>		<span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.logging.log4j<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>		<span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>log4j-core<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>		<span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.8.2<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>	<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>	<span class="hljs-comment">&lt;!-- https://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper --&gt;</span>	<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>		<span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.zookeeper<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>		<span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>zookeeper<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>		<span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.4.10<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>	<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h3 id="3-3-3-拷贝log4j-properties文件到项目根目录"><a href="#3-3-3-拷贝log4j-properties文件到项目根目录" class="headerlink" title="3.3.3 拷贝log4j.properties文件到项目根目录"></a>3.3.3 拷贝log4j.properties文件到项目根目录</h3><p>需要在项目的src/main/resources目录下，新建一个文件命名为“log4j.properties”，在文件中填入。</p>
<p><img src="https://img-blog.csdnimg.cn/20210603191257780.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java">log4j.rootLogger=INFO, stdout  log4j.appender.stdout=org.apache.log4j.ConsoleAppender  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout  log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n  log4j.appender.logfile=org.apache.log4j.FileAppender  log4j.appender.logfile.File=target/spring.log  log4j.appender.logfile.layout=org.apache.log4j.PatternLayout  log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n <br></code></pre></td></tr></table></figure>

<h3 id="3-3-4-创建ZooKeeper客户端"><a href="#3-3-4-创建ZooKeeper客户端" class="headerlink" title="3.3.4 创建ZooKeeper客户端"></a>3.3.4 创建ZooKeeper客户端</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 创建ZooKeeper客户端,客户端连接服务端public static void init() throws IOException &#123;    zkClient = new ZooKeeper(connectString, sessionTimeout, new Watcher() &#123;        @Override        public void process(WatchedEvent watchedEvent) &#123;        &#125;    &#125;);&#125;public static void main(String[] args) throws Exception &#123;    init();&#125;</span><br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/20210603193635207.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-3-5-创建子节点"><a href="#3-3-5-创建子节点" class="headerlink" title="3.3.5 创建子节点"></a>3.3.5 创建子节点</h3><p><strong>如果是远程连接操作的虚拟机中的zk，一定要记得：</strong></p>
<p>关闭 linux 环境中的防火墙！<br>关闭 linux 环境中的防火墙！<br>关闭 linux 环境中的防火墙！</p>
<p><img src="https://img-blog.csdnimg.cn/20210604120635764.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 创建子节点public static void create() throws Exception &#123;    // 参数1：要创建的节点的路径    String path = &quot;/testCreate&quot;;    // 参数2：节点数据    byte[] data = &quot;ht&quot;.getBytes();    // 参数3：节点权限    List&lt;ACL&gt; acls = Ids.OPEN_ACL_UNSAFE;    // 参数4：节点的类型    CreateMode createMode = CreateMode.PERSISTENT;    String nodeCreated = zkClient.create(path, data, acls, createMode);    System.out.println(nodeCreated);&#125;public static void main(String[] args) throws Exception &#123;    init();    create();&#125;</span><br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/20210604120802939.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p><img src="https://img-blog.csdnimg.cn/20210604120809334.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p><img src="https://img-blog.csdnimg.cn/2021060412082545.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p><img src="https://img-blog.csdnimg.cn/20210604120846687.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-3-6-获取子节点并监听节点变化"><a href="#3-3-6-获取子节点并监听节点变化" class="headerlink" title="3.3.6 获取子节点并监听节点变化"></a>3.3.6 获取子节点并监听节点变化</h3><p>获取节点</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">getDataAndWatch</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> KeeperException, InterruptedException &#123;    List&lt;String&gt; children = zkClient.getChildren(<span class="hljs-string">&quot;/&quot;</span>, <span class="hljs-literal">true</span>);    <span class="hljs-keyword">for</span> (String child : children) &#123;        System.out.println(child);    &#125;    <span class="hljs-comment">// 延时阻塞    Thread.sleep(Long.MAX_VALUE);&#125;</span><br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 创建ZooKeeper客户端,客户端连接服务端public static void init() throws IOException &#123;    zkClient = new ZooKeeper(connectString, sessionTimeout, new Watcher() &#123;        // 监听        @Override        public void process(WatchedEvent watchedEvent) &#123;            List&lt;String&gt; children = null;            System.out.println(&quot;---------start---------&quot;);            try &#123;                children = zkClient.getChildren(&quot;/&quot;, true);                for (String child : children) &#123;                    System.out.println(child);                &#125;            &#125; catch (Exception e) &#123;                e.printStackTrace();            &#125;            System.out.println(&quot;---------end---------&quot;);        &#125;    &#125;);&#125;</span><br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> Exception &#123;    init();<span class="hljs-comment">//  create();    getDataAndWatch();&#125;</span><br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/20210604122931552.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p><img src="https://img-blog.csdnimg.cn/20210604122941937.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-3-7-判断Znode是否存在"><a href="#3-3-7-判断Znode是否存在" class="headerlink" title="3.3.7 判断Znode是否存在"></a>3.3.7 判断Znode是否存在</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 判断节点是否存在public static void isExist() throws KeeperException, InterruptedException &#123;    Stat exists = zkClient.exists(&quot;/sanguo&quot;, false);    System.out.println(exists==null ? &quot;not exist&quot; : &quot;exist&quot;);&#125;public static void main(String[] args) throws Exception &#123;    init();//  create();//  getDataAndWatch();    isExist();&#125;</span><br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/20210604124236461.png" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h2 id="3-4-🔺-监听服务器节点动态上下线案例"><a href="#3-4-🔺-监听服务器节点动态上下线案例" class="headerlink" title="3.4 🔺 监听服务器节点动态上下线案例"></a>3.4 🔺 监听服务器节点动态上下线案例</h2><h3 id="3-4-1-需求"><a href="#3-4-1-需求" class="headerlink" title="3.4.1 需求"></a>3.4.1 需求</h3><p>某分布式系统中，主节点可以有多台，可以动态上下线，<strong>任意一台客户端都能实时感知到主节点服务器的上下线</strong>。</p>
<h3 id="3-4-2-需求分析"><a href="#3-4-2-需求分析" class="headerlink" title="3.4.2 需求分析"></a>3.4.2 需求分析</h3><p><img src="https://img-blog.csdnimg.cn/20210604160202421.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h3 id="3-4-3-具体实现"><a href="#3-4-3-具体实现" class="headerlink" title="3.4.3 具体实现"></a>3.4.3 具体实现</h3><p>① 先在集群上创建/servers节点</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">create /servers <span class="hljs-string">&quot;servers&quot;</span><br></code></pre></td></tr></table></figure>

<p>② 服务器端向Zookeeper注册代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">DistributeServer</span> &#123;    <span class="hljs-keyword">private</span> <span class="hljs-type">String</span> <span class="hljs-variable">connectString</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;192.168.44.129:2181,192.168.44.129:2182,192.168.44.129:2183&quot;</span>;    <span class="hljs-keyword">private</span> <span class="hljs-type">int</span> <span class="hljs-variable">sessionTimeout</span> <span class="hljs-operator">=</span>  <span class="hljs-number">10000</span>;    <span class="hljs-keyword">private</span> <span class="hljs-type">ZooKeeper</span> <span class="hljs-variable">zk</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;    <span class="hljs-keyword">private</span> <span class="hljs-type">String</span> <span class="hljs-variable">parentNode</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;/servers&quot;</span>;    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-type">String</span> <span class="hljs-variable">hostname</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;ht&quot;</span>;    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> Exception &#123;        <span class="hljs-type">DistributeServer</span> <span class="hljs-variable">server</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">DistributeServer</span>();        <span class="hljs-comment">// 服务端获取和zk的连接        server.getConnect();        // 注册服务器        server.registServer(hostname);        // 业务逻辑        server.businesss(hostname);    &#125;    // 注册服务器    public void registServer(String hostname) throws Exception&#123;        String create = zk.create(parentNode + &quot;/server&quot;, hostname.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);        System.out.println(hostname +&quot; is online &quot;+ create);    &#125;    // 业务逻辑代码    private void businesss(String hostname) throws InterruptedException &#123;        System.out.println(hostname+&quot; is working ...&quot;);        // 延时阻塞        Thread.sleep(Long.MAX_VALUE);    &#125;    // 创建到zookeeper的客户端连接    private void getConnect() throws IOException &#123;        zk = new ZooKeeper(connectString, sessionTimeout, new Watcher() &#123;            @Override            public void process(WatchedEvent watchedEvent) &#123;            &#125;        &#125;);    &#125;    &#125;</span><br></code></pre></td></tr></table></figure>

<p>③ 客户端代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">DistributeClient</span> &#123;    <span class="hljs-keyword">private</span> <span class="hljs-type">String</span> <span class="hljs-variable">connectString</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;192.168.44.129:2181,192.168.44.129:2182,192.168.44.129:2183&quot;</span>;    <span class="hljs-keyword">private</span> <span class="hljs-type">int</span> <span class="hljs-variable">sessionTimeout</span> <span class="hljs-operator">=</span>  <span class="hljs-number">10000</span>;    <span class="hljs-keyword">private</span> <span class="hljs-type">ZooKeeper</span> <span class="hljs-variable">zk</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;    <span class="hljs-keyword">private</span> <span class="hljs-type">String</span> <span class="hljs-variable">parentNode</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;/servers&quot;</span>;    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> Exception &#123;        <span class="hljs-type">DistributeClient</span> <span class="hljs-variable">client</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">DistributeClient</span>();        <span class="hljs-comment">// 1获取zk连接        client.getConnect();        // 2获取servers的子节点信息，从中获取服务器信息列表        client.getServerList();        // 3业务进程启动        client.business();    &#125;    // 3业务进程启动    private void business() throws InterruptedException &#123;        System.out.println(&quot;client is working ...&quot;);        Thread.sleep(Long.MAX_VALUE);    &#125;    private void getServerList() throws KeeperException, InterruptedException &#123;        // 1获取服务器子节点信息，并且对父节点进行监听        List&lt;String&gt; children = zk.getChildren(parentNode, true);        // 2存储服务器信息列表        ArrayList&lt;String&gt; servers = new ArrayList&lt;&gt;();        // 3遍历所有节点，获取节点中的主机名称信息        for (String child : children) &#123;//            byte[] data = zk.getData(parentNode + &quot;/&quot; + child, false, null);////            servers.add(new String(data));            servers.add(child);        &#125;        // 4 打印服务器列表的信息        System.out.println(servers);    &#125;    // 创建客户端和zookeeper的连接    private void getConnect() throws IOException &#123;        zk = new ZooKeeper(connectString, sessionTimeout, new Watcher() &#123;            @Override            public void process(WatchedEvent watchedEvent) &#123;                // 再次启动监听                try &#123;                    getServerList();                &#125; catch (Exception e) &#123;                    e.printStackTrace();                &#125;            &#125;        &#125;);    &#125;&#125;</span><br></code></pre></td></tr></table></figure>

<p>④ 测试</p>
<p><img src="https://img-blog.csdnimg.cn/2021060417021135.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<p><img src="https://img-blog.csdnimg.cn/20210604170217605.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h1 id="4-企业面试真题"><a href="#4-企业面试真题" class="headerlink" title="4 企业面试真题"></a>4 企业面试真题</h1><p><img src="https://img-blog.csdnimg.cn/20210604160317967.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTI2MDM4NQ==,size_16,color_FFFFFF,t_70" srcset="/my-hexo-fluid/img/loading.gif" lazyload alt="å¨è¿éæå¥å¾çæè¿°"></p>
<h1 id="5-参考链接"><a href="#5-参考链接" class="headerlink" title="5 参考链接"></a>5 参考链接</h1><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_45260385/article/details/117481003?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163067077116780264020597%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&amp;request_id=163067077116780264020597&amp;biz_id=0&amp;utm_medium=distribute.pc_search_result.none-task-blog-2~all~baidu_landing_v2~default-4-117481003.first_rank_v2_pc_rank_v29&amp;utm_term=zookeeper%E7%AC%94%E8%AE%B0&amp;spm=1018.2226.3001.4187">https://blog.csdn.net/weixin_45260385/article/details/117481003?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163067077116780264020597%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&amp;request_id=163067077116780264020597&amp;biz_id=0&amp;utm_medium=distribute.pc_search_result.none-task-blog-2~all~baidu_landing_v2~default-4-117481003.first_rank_v2_pc_rank_v29&amp;utm_term=zookeeper%E7%AC%94%E8%AE%B0&amp;spm=1018.2226.3001.4187</a></p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/my-hexo-fluid/categories/%E5%90%8E%E7%AB%AF/" class="category-chain-item">后端</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/my-hexo-fluid/tags/Java/">#Java</a>
      
        <a href="/my-hexo-fluid/tags/Zookepper/">#Zookepper</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Zookepper学习笔记</div>
      <div>https://wskh0929.gitee.io/2023/01/01/Zookepper学习笔记/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>WSKH0929</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年1月1日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/my-hexo-fluid/2023/01/01/Swagger-%E7%8B%82%E7%A5%9E%E7%AC%94%E8%AE%B0/" title="Swagger-狂神笔记">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Swagger-狂神笔记</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/my-hexo-fluid/2023/01/01/R-language-visualization/" title="R language visualization">
                        <span class="hidden-mobile">R language visualization</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"jkBkMZcW6P8K0bQScoJqvQrX-9Nh9j0Va","appKey":"1k6toLLZa7DFnrENpqSs9Ouw","path":"window.location.pathname","placeholder":"留言仅限讨论，禁止广告等行为","avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"https://jkbkmzcw.lc-cn-e1-shared.com","emojiCDN":null,"emojiMaps":null,"enableQQ":false},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/my-hexo-fluid/js/events.js" ></script>
<script  src="/my-hexo-fluid/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/my-hexo-fluid/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/my-hexo-fluid/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/love.js"></script>
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/xiaoxingxing.js"></script>
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/xiaoxuehua.js"></script>
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/caidai.js"></script>



<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/my-hexo-fluid/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
